// Copyright (C) 1998-2008, Sumisho Computer Systems Corp. All Rights Reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @author Hitoshi Okada
 */

package com.curlap.orb.generator;

/*
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.Enumeration;
import java.io.File;
*/

/**
 * JarFileLoader
 */
public class JarFileLoader
{
    /*
    JarFileProperty jarFileProperty;
    
    public JarFileLoader(String jarfile)
    {
        jarFileProperty = new JarFileProperty(jarfile);
        try 
        {
            for (Enumeration enumeration = (new JarFile(new File(jarfile))).entries(); enumeration.hasMoreElements();) 
            {
                ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
                if (!zipentry.isDirectory() && !zipentry.getName().startsWith(("META-INF")))
                {
                    String classPath = zipentry.getName();
                    String p = classPath.substring(0, classPath.lastIndexOf('/')).replace('/', '.');
                    String c = classPath.substring(0, classPath.lastIndexOf('.')).replace('/', '.');
                    PackageProperty packageProperty = jarFileProperty.getPackageProperty(p);
                    if (packageProperty != null)
                    {
                        packageProperty.addClassProperty(new ClassProperty(c));
                    }
                    else 
                    {
                        packageProperty = new PackageProperty(p);
                        packageProperty.addClassProperty(new ClassProperty(c));
                        jarFileProperty.addPackageProperty(packageProperty);
                    }
                }
            }
        }
        catch(Exception e)
        {
            // FIXME:
            e.printStackTrace();
        }
    }

    public JarFileProperty getJarFileProperty()
    {
        return jarFileProperty;
    }

    public static void main(String[] args)
    {
        JarFileLoader v = new JarFileLoader("D:\\tmp\\lab\\workspace\\curl-orb\\WEB-INF\\lib\\curl-serialize.jar");
        PackageProperty[] p = v.jarFileProperty.getPackageProperties();
        for (int i = 0; i < p.length; i++)
        {
            System.out.println(p[i].getName());
            ClassProperty[] c = p[i].getClassProperties();
            for (int j = 0; j < c.length; j++)
            {
                MethodProperty[] m = c[j].getMethodProperties();
                System.out.println(" " + c[j].getName() + " " + c[j].getSuperClass());

                for (int k = 0; k < m.length; k++)
                System.out.println(m[k].getName());
            }
        }
    }
    */
}
